package com.anzym.android.kegdroidkey;

import android.content.Context;
import android.graphics.Bitmap;
import android.location.LocationManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.anzym.android.kegdroidkey.R;
import com.anzym.android.kegdroidlibrary.models.Beer;
import java.util.ArrayList;

public class BeerListAdapter extends BaseAdapter {
    
    private static final String TAG = BeerListAdapter.class.getSimpleName();
    private ArrayList<Beer> beers;  
    private static LayoutInflater inflater = null;
    LocationManager locManager;

    
    public BeerListAdapter (Context ctx, ArrayList<Beer> b) {
        this.beers = b;
        this.inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return beers.size();
    }

    @Override
    public Object getItem(int position) {
        return beers.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    
    public class ViewHolder {
        private TextView beerName;
        private TextView beerABV;
        private TextView beerIBU;
        //private TextView beerVolumeRemaining;
        private ImageView beerImage;
        
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = inflater.inflate(R.layout.beer_order_item, null);
            holder = new ViewHolder();
            holder.beerName = (TextView) convertView.findViewById(R.id.beer_item_name);
            holder.beerABV = (TextView) convertView.findViewById(R.id.beer_item_abv);
            holder.beerIBU= (TextView) convertView.findViewById(R.id.beer_item_ibu);
            holder.beerImage = (ImageView) convertView.findViewById(R.id.beer_item_image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        Beer b = beers.get(position);
        holder.beerName.setText(b.getName());
        holder.beerABV.setText("ABV: " + new Double(b.getAbv()).toString());
        holder.beerIBU.setText("IBU: " + new Integer(b.getIbu()).toString());
        holder.beerImage.setImageBitmap(Bitmap.createScaledBitmap(b.getImage(),
                100, 200, false));
        return convertView;
    }
}
